function CEEffectLuncher(effectId,from,tos){
	var effect = CEFindEffectInData(effectId);
	var events = new Array();
	var initiative = false;
	var range = 0;
	var damage = new Array();
	var type = "chess";
	console.log("效果："+effect.effect);
	console.log("参数："+effect.parameter);
	if(effect != null){
		var effects = effect.effect.split(",");
		var parameters = effect.parameter.split(",");
		var chessEffect = new ChessEffect();
		for(var i in effects){
			console.log("　　词条："+effects[i]);
			switch(effects[i]){
				case "抬起":{
					initiative = true;
					break;
				}
				case "全屏":{
					range = -1;
					break;
				}
				case "范围":{
					range = parameters[i];
					break;
				}
				case "他人":{
					type = "other";
					break;
				}
				case "敌军":{
					type = "enemy";
					break;
				}
				case "友军":{
					type = "ally";
					break;
				}
			}
		}
		if(initiative){
			_GAList.push(new GameAnm("抬起",0,TargetToMulti(from)));
		}
		if(range){
			if(range == -1){
				tos = SAllToRange();
			}
			else{
				tos = STargetToRange(from,tos,range,type);
			}
		}
		if(effect.animation != undefined){
			var to = new Array();
			for(var i in tos){
				to.push(tos[i]);
			}
			if(to.length!=0)
				_GAList.push(new GameAnm(effect.animation,effect.animationNo,to));
		}
		var out = new Array();
		for(var i in tos){
			out.push(false);
		}
		for(var i in effects){
			for(var j in tos){
				console.log("　　词条："+effects[i]);
				if(!out[j] && CFindByPosition(tos[j]) != null){
					if(j==0 && CEImmuneFind(effect.effect,CFindByPosition(tos[j]).id)){
						out[j] = true;
					}
					if(CEIgnoreFind(effects[i],CFindByPosition(tos[j]).id)){
						break;
					}
					switch(effects[i]){
						case "目标生命值低于":{
							if(CSgetState("HP",CFindByPosition(tos[j]).id) >= parameters[i]){
								out[j] = true;
							}
							break;
						}
						case "攻击":{
							for(var k in tos){
								CEBuffPlacer(tos[k],from);
								CSBeHit(tos[k],from);
							}
							var to = new Array();
							to.push(tos[j]);
							_GEEventList.push(new GEEvent("效果",new ChessEffect("Attack Damage",from,to)));
							break;
						}
						case "伤害":{
							if(CSDamage(CFindByPosition(tos[j]).id,CECounter(parameters[i],from,_board[tos[j].x][tos[j].y].id),from)){
								damage.push(CFindByPosition(tos[j]).id);
							}
							break;
						}
						case "移除生命":{
							CSRemoveHP(CFindByPosition(tos[j]).id,from);
							break;
						}
						case "击杀增益":{
							if(CSgetState("伤害",CFindByPosition(tos[j]).id)>=CSgetState("HP上限",CFindByPosition(tos[j]).id)){
								var to = new Array();
								var chess = CFindById(from);
								to.push(chess.position);
								_GEEventList.push(new GEEvent("效果",new ChessEffect(parameters[i],from,to)));
							}
							break;
						}
						case "击杀效果":{
							if(CSgetState("伤害",CFindByPosition(tos[j]).id)>=CSgetState("HP上限",CFindByPosition(tos[j]).id)){
								var to = new Array();
								to.push(tos[j]);
								_GEEventList.push(new GEEvent("效果",new ChessEffect(parameters[i],from,to)));
							}
							break;
						}
						case "消灭":{
							CSDestory(CFindByPosition(tos[j]).id,from)
							break;
						}
						case "治疗":{
							CSHeal(CFindByPosition(tos[j]).id,CECounter(parameters[i],from,_board[tos[j].x][tos[j].y].id),from);
							break;
						}
						case "移除效果":{
							CEEffectRemove(CFindByPosition(tos[j]).id,parameters[i]);
							break;
						}
						case "净化":{
							CFindByPosition(tos[j]).effect = new Array();
							break;
						}
						case "回复法力":{
							CSRegenerateMana(CFindByPosition(tos[j]).id,parameters[i]);
							break;
						}
						case "永久变形":{
							CFindByPosition(tos[j]).chess = CFindInData(parameters[i]);
							CFindByPosition(tos[j]).sprite.removeChild(CFindByPosition(tos[j]).head,true);
							CFindByPosition(tos[j]).head = new HeadSprite(CFindByPosition(tos[j]).chess);
							CFindByPosition(tos[j]).sprite.addChild(CFindByPosition(tos[j]).head, 2, "head");
							CFindByPosition(tos[j]).skill = new SSkillLuncher(CFindByPosition(tos[j]).chess.skill);
							GUIShowSkillIcon(_GDNowChess);
							if(CSgetState("MP",CFindByPosition(tos[j]).id) > CSgetState("MP上限",CFindByPosition(tos[j]).id)){
								CFindByPosition(tos[j]).mp = CSgetState("MP上限",CFindByPosition(tos[j]).id);
							}
							break;
						}
						case "升级":{
							var temp = CFindInData(parameters[i]).effect;
							CFindByPosition(tos[j]).chess = CFindInData(parameters[i]);
							CFindByPosition(tos[j]).chess.effect = temp;
							CFindByPosition(tos[j]).sprite.removeChild(CFindByPosition(tos[j]).head,true);
							CFindByPosition(tos[j]).head = new HeadSprite(CFindByPosition(tos[j]).chess);
							CFindByPosition(tos[j]).sprite.addChild(CFindByPosition(tos[j]).head, 2, "head");
							CFindByPosition(tos[j]).skill = new SSkillLuncher(CFindByPosition(tos[j]).chess.skill);
							GUIShowSkillIcon(_GDNowChess);
							CFindByPosition(tos[j]).mp = 0;
							CFindByPosition(tos[j]).hit = 0;
							break;
						}
						case "置换棋子":{
							CFindByPosition(tos[j]).chess = CFindInData(parameters[i]);
							CFindByPosition(tos[j]).sprite.removeChild(CFindByPosition(tos[j]).head,true);
							CFindByPosition(tos[j]).head = new HeadSprite(CFindByPosition(tos[j]).chess);
							CFindByPosition(tos[j]).sprite.addChild(CFindByPosition(tos[j]).head, 2, "head");
							CFindByPosition(tos[j]).skill = new SSkillLuncher(CFindByPosition(tos[j]).chess.skill);
							GUIShowSkillIcon(_GDNowChess);
							CFindByPosition(tos[j]).mp = CSgetState("MP上限",CFindByPosition(tos[j]).id);
							CFindByPosition(tos[j]).hit = 0;
							break;
						}
						case "结附":{
							CEEffectStack(CFindByPosition(tos[j]).id,parameters[i],from);
							break;
						}
						case "对己结附":{
							CEEffectStack(from,parameters[i],from);
							break;
						}
					}
				}
				else if(!out[j] && CFindById(from) != null){
					switch(effects[i]){
						case "召唤":{
							if(null == _board[tos[j].x][tos[j].y] && CFindById(from)!=null){
								_board[tos[j].x][tos[j].y] = ChessLoader(parameters[i],CFindById(from).team,"",undefined,tos[j]);
								g_GBTouchLayer.addChild(_board[tos[j].x][tos[j].y].sprite);
								_GDChessList.push(_board[tos[j].x][tos[j].y]);
							}
							break;
						}
						case "召唤狂战":{
							if(null == _board[tos[j].x][tos[j].y] && CFindById(from)!=null){
								_board[tos[j].x][tos[j].y] = ChessLoader(parameters[i],CFindById(from).team,"狂战",undefined,tos[j]);
								g_GBTouchLayer.addChild(_board[tos[j].x][tos[j].y].sprite);
								_GDChessList.push(_board[tos[j].x][tos[j].y]);
							}
							break;
						}
					}
				}
			}
		}
		if(damage.length)
			_GAList.push(new GameAnm("震动",0,damage));
	}
	if(initiative){
		_GAList.push(new GameAnm("恢复",0,TargetToMulti(from)));
	}
	_GLState = "动画运行";
}

function ChessEffect(id,from,tos){
	this.id = id;
	this.from = from;
	this.tos = tos;
}

function CEFindEffectInData(effectId){
	for(var i=0;i<_effect.length;i++){
		if(_effect[i].id == effectId)
			return _effect[i];
	}
	return null;
}

function CEKeywords(keyword,parameter){
	this.keyword = keyword;
	this.parameter = parameter;
}

/**
 * 返回某数值
 * 
 * @param param
 *            参数
 * @param from
 *            来源id
 * @param to
 *            目标id
 * @returns {integer} 伤害值
 */
function CECounter(param,from,to){
	if(isNaN(param)){
		var counter = 0;
		var parameters = param.split("+");
		for(var i in parameters){
			if(isNaN(parameters[i])){
				switch(parameters[i]){
					case "生命值":{
						counter += CSgetState("生命值",from);
						break;
					}
					case "攻击力":{
						counter += CSgetState("攻击力",from);
						break;
					}
					case "目标生命值":{
						counter += CSgetState("生命值",to);
						break;
					}
					case "目标缺失生命值":{
						counter += (CSgetState("HP上限",to)-CSgetState("HP",to));
						break;
					}
					case "目标攻击力":{
						counter += CSgetState("攻击力",to);
						break;
					}
					case "缺失法力值":{
						counter += (CSgetState("MP上限",from)-CSgetState("MP",from));
						break;
					}
					default:{
						var data = parameters[i].split(":");
						switch(data[0]){
							case "目标结附":{
								var effectList = CEEffectGetter(to);
								for(var i in effectList){
									var effects_1 = effectList[i].effect.split(",");
									var parameters_1 = effectList[i].parameter.split(",");
									for(var j in effects_1){
										if(data[1] == effects_1[j]){
											counter += parseInt(parameters_1[j]);
										}
									}
								}
								break;
							}
							case "自身结附":{
								var effectList = CEEffectGetter(from);
								for(var i in effectList){
									var effects_1 = effectList[i].effect.split(",");
									var parameters_1 = effectList[i].parameter.split(",");
									for(var j in effects_1){
										if(data[1] == effects_1[j]){
											counter += parseInt(parameters_1[j]);
										}
									}
								}
								break;
							}
							default:{
								console.log("数据调用名" +data[0]+ "错误");
								return 0;
							}
						}
						break;
					}
				}
			}
			else{
				counter += parseInt(parameters[i]);
			}
		}
		return counter;
	}
	else{
		return parseInt(param);
	}
};

// 状态生效
function CEEffectsTrigger(){
	effectList = CEEffectGetter(_GDNowChess.id)
	for(var i =0 ; i< effectList.length;i++){
		console.log("回合开始执行效果："+effectList[i].id);
		var effects = effectList[i].effect.split(",");
		var parameters = effectList[i].parameter.split(",");
		for(var j in effects){
			if(effects[j] == "持续治疗"){
				CSHeal(_GDNowChess.id,parameters[j],_GDNowChess.id);
			}
			if(effects[j] == "持续回复法力"){
				CSRegenerateMana(_GDNowChess.id,parameters[j]);
			}
			if(effects[j] == "持续伤害"){
				CSDamage(_GDNowChess.id,parameters[j],_GDNowChess.id);
			}
			if(effects[j] == "持续移除生命"){
				CSRemoveHP(_GDNowChess.id,parameters[j],_GDNowChess.id);
			}
		}
	}
};

// 状态结束
function CEEffectsEnd(){
	var temp = CFindById(_GDNowChess.id);
	if(temp == null)
		return;
	for(var i = 0;i < temp.effect.length;i++){
		var effects = temp.effect[i].effect.split(",");
		var parameters = temp.effect[i].parameter.split(",");
		for(j in effects){
			if(effects[j] == "持续" && parameters[j] != "0"){
				parameters[j] = parseInt(parameters[j]-1).toString();
				if(parameters[j] == "0"){
					temp.effect.splice(i,1);
					i--;
				}
				else
					temp.effect[i].parameter = parameters.join(",");
			}
		}
	}
};

/**
 * 效果查询器
 * 
 * @param id
 *            查询id
 */
function CEEffectGetter(id){
	var effectList = new Array();
	var chess = CFindById(id);
	if(chess == null){
		console.log("不存在的目标ID:"+id);
		return;
	}
	for(var i in chess.skill){
		if(chess.skill[i].type == "passive"){
			var effects = chess.skill[i].effect.split(",");
			for(var j in effects){
				effectList.push(CEFindEffectInData(effects[j]));
			}
		}
	}
	effectList = effectList.concat(CEAuraGetter(id));
	effectList = effectList.concat(chess.effect);
	return effectList;
}

/**
 * 效果移除器
 * 
 * @param id
 *            查询id
 */
function CEEffectRemove(id,effectId){
	var effectList = new Array;
	for(var effect in CFindById(id).effect.length){
		if(effect.id != effectId){
			effectList.push(effect);
		}
	}
	CFindById(id).effect = effectList;
	return effectList;
}

/**
 * 附加效果查询器
 * 
 * @param id
 *            来源id
 */
function CEOuterEffectGetter(id){
	var effectList = CEAuraGetter(id);
	effectList = effectList.concat(CFindById(id).effect);
	return effectList;
}

/**
 * 效果叠加器
 * 
 * @param id
 *            来源id
 * @param effectId
 *            效果id
 */
function CEEffectStack(id,effectId,fromId){
	console.log("进入叠加器："+effectId);
	var stack = 0;
	var no = 0;
	var effect = CEFindEffectInData(effectId);
	var effects = effect.effect.split(",");
	var parameters = effect.parameter.split(",");
	var chess = CFindById(id);
	for(var i in effects){
		switch(effects[i]){
			case "叠加":{
				stack = parameters[i];
			}
		}
	}
	for(var i in chess.effect){
		if(chess.effect[i].id == effect.id){
			no ++;
			if(!stack){
				chess.effect.splice(i,1);
				i--;
			}
		}
	}
	if(stack > 0){
		for(var i in chess.effect){
			if(chess.effect[i].id == effect.id){
				if(no >= stack){
					chess.effect.splice(i,1);
					i--;
					no--;
				}
			}
		}
	}
	console.log("特效插入："+id);
	var tempEffect = JSON.parse(JSON.stringify(CEFindEffectInData(effectId)));
	tempEffect.from = fromId;
	chess.effect.push(tempEffect);
};

/**
 * 光环查询器
 * 
 * @param id
 *            被判断棋子ID
 */
function CEAuraGetter(id){
	var effectList = new Array();
	var temp = CFindById(id);
	if(temp == null){
		console.log("不存在的目标ID:"+id);
		return effectList;
	}
	for(var i in _GDChessList){
		for(var j in _GDChessList[i].skill){
			if(_GDChessList[i].skill[j].type == "aura"){
				if(_GDChessList[i].skill[j].target == "ally"){
					if(Range(_GDChessList[i].position,temp.position,parseInt(_GDChessList[i].skill[j].range)) && _GDChessList[i].team == temp.team){
						effectList.push(CEEffectFrom(_GDChessList[i].id,_GDChessList[i].skill[j].effect));
					}
				}
				else if(_GDChessList[i].skill[j].target == "enemy"){
					if(Range(_GDChessList[i].position,temp.position,parseInt(_GDChessList[i].skill[j].range)) && _GDChessList[i].team != temp.team){
						effectList.push(CEEffectFrom(_GDChessList[i].id,_GDChessList[i].skill[j].effect));
					}
				}
				else{
					if(Range(_GDChessList[i].position,temp.position,parseInt(_GDChessList[i].skill[j].range))){
						effectList.push(CEEffectFrom(_GDChessList[i].id,_GDChessList[i].skill[j].effect));
					}
				}
			}
		}
	}
	return effectList;
}

/**
 * 法球查询器
 * 
 * @param to
 *            目标位置
 * @param from
 *            来源ID
 */
function CEBuffPlacer(to,from){
	var effectList = CEEffectGetter(from);
	for(var i in effectList){
		var effects = effectList[i].effect.split(",");
		var parameters = effectList[i].parameter.split(",");
		for(var j in effects){
			if(effects[j] == "对敌攻击特效"){
				var tos = new Array();
				tos.push(to);
				_GEEventList.push(new GEEvent("效果",new ChessEffect(parameters[j],from,tos)));
			}
			if(effects[j] == "对己攻击特效"){
				var tos = new Array();
				tos.push(CFindById(from).position);
				_GEEventList.push(new GEEvent("效果",new ChessEffect(parameters[j],from,tos)));
			}
		}
	}
};

/**
 * 字段查询器
 * 
 * @param id
 *            查询目标id
 * @param name
 *            字段名称
 */
function CEEffectFind(id,name){
	var effectList = CEEffectGetter(id);
	for(var i in effectList){
		var effects = effectList[i].effect.split(",");
		for(var j in effects){
			if(effects[j] == name){
				var parameters = effectList[i].parameter.split(",");
				return parameters[j];
			}
		}
	}
	return null;
}

/**
 * 免疫查询器（查询免疫含有固定词条的技能）
 * 
 * @param effect
 *            查询目标效果
 * @param id
 *            目标棋子id
 */
function CEImmuneFind(effect,id){
	var effects = effect.split(",");
	var effectList = CEEffectGetter(id);
	for(var i in effects){
		for(var j in effectList){
			var temp = effectList[j].effect.split(",");
			var parameters = effectList[j].parameter.split(",");
			for(var k in temp){
				if(temp == "免疫" && effects[i] == parameters[k]){
					return true;
				}
			}
		}
	}
	return false;
}

/**
 * 忽略查询器（查询忽略技能中固定词条的效果）
 * 
 * @param name
 *            查询目标词条
 * @param id
 *            目标棋子id
 */
function CEIgnoreFind(name,id){
	var effectList = CEEffectGetter(id);
	for(var i in effectList){
		var effects = effectList[i].effect.split(",");
		var parameters = effectList[i].parameter.split(",");
		for(var j in effects){
			if(effects[j]=="忽略"&& parameters[j] == name){
				return true;
			}
		}
	}
	return false;
}

/**
 * 为效果添加来源并深复制
 * 
 * @param from
 *            效果来源
 * @param effectId
 *            效果ID
 */
function CEEffectFrom(from,effectId){
	var tempEffect = JSON.parse(JSON.stringify(CEFindEffectInData(effectId)));
	tempEffect.from = from;
	return tempEffect;
}